<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改横向课题')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-apply-edit" th:object="${sciHorizontalApply}">
            <input type="hidden" id="reAmount" name="reAmount">
            <input type="hidden" id="accountData" name="accountData">
            <input type="hidden" id="reamountUrl" name="reamountUrl">
<!--            <input name="amountType" id="amountType" type="hidden" value="立项">-->
            <input name="id" id="ktid" th:field="*{id}" type="hidden">
            <input type="hidden" id="applyId" name = "applyId"  >
            <input name="state" id="state" th:field="*{state}" type="hidden">
            <h4 class="form-header h4">基本信息</h4>
            <div class="row">
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">申请人：</label>
                    <div class="col-sm-8">
<!--                        <input name="userId" th:field="*{userId}" class="form-control" type="text" required>-->
                        <select name="userId" class="form-control m-b" disabled="true">
                            <option th:each="user : ${sysUsers1}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ user.userId == sciHorizontalApply.userId}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课题编号：</label>
                    <div class="col-sm-8">
                        <input   th:field="*{topNumber}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课题类型：</label>
                    <div class="col-sm-8">
                        <select name="topType" class="form-control" th:with="type=${@dict.getType('sci_top_type')}" required>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{topType}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课题名称：</label>
                    <div class="col-sm-8">
                        <input name="topName" th:field="*{topName}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">甲方：</label>
                    <div class="col-sm-8">
                        <input name="partyA" th:field="*{partyA}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">乙方：</label>
                    <div class="col-sm-8">
                        <input name="partyB" th:field="*{partyB}"  class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">项目金额：</label>
                    <div class="col-sm-8">
                        <div class="input-group ">
                            <input name="amount" th:field="*{amount}" class="form-control" type="number" required>
                            <span class="input-group-addon">
                                <a href="#" title="上传到账金额"  data-toggle="modal" data-target="#myModal"><i class="fa fa-plus-circle" ></i>到账金额</a>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="col-sm-4 control-label is-required">申请日期：</label>
                            <div class="col-sm-8">
                                <div class="input-group date">
                                   <input name="signingData" autocomplete="off" th:field="*{signingData}" th:value="${#dates.format(signingData, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                </div>
                            </div>
                        </div>
                    </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">第一负责人：</label>
                    <div class="col-sm-8">
<!--                        <input name="firstPersonId" th:field="*{firstPersonId}" class="form-control" type="text" required>-->
                        <select name="firstPersonId" class="form-control m-b" required>
                            <option value="">无</option>
                            <option th:each="user : ${sysUsers1}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciHorizontalApply.firstPersonId}"></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">第二负责人：</label>
                    <div class="col-sm-8">
<!--                        <input name="secondPersonTask" th:field="*{secondPersonTask}" class="form-control" type="text" required>-->
                        <select name="secondPersonId" class="form-control m-b" required>
                            <option value="">无</option>
                            <option th:each="user : ${sysUsers1}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciHorizontalApply.secondPersonId}" ></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">第三负责人：</label>
                    <div class="col-sm-8">
<!--                        <input name="thirdPersonId" th:field="*{thirdPersonId}" class="form-control" type="text" required>-->
                        <select name="thirdPersonId" class="form-control m-b" required>
                            <option value="">无</option>
                            <option th:each="user : ${sysUsers1}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciHorizontalApply.thirdPersonId}"  ></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">第四负责人：</label>
                    <div class="col-sm-8">
<!--                        <input name="fourthPersonId" th:field="*{fourthPersonId}" class="form-control" type="text" required>-->
                        <select name="fourthPersonId" class="form-control m-b" required>
                            <option value="">无</option>
                            <option th:each="user : ${sysUsers1}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciHorizontalApply.fourthPersonId}"  ></option>
                        </select>
                    </div>
                </div>
            </div>


            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">开题报告：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="contract" th:field="*{filing}">
                       <div class="file-loading">
                            <input class="form-control file-uploada" id="contract" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">开题备案表：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="filing" th:field="*{contract}">
                       <div class="file-loading">
                            <input class="form-control file-uploadb" id="filing" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
            </div>

            <h4 class="form-header h4">退回原因</h4>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
        window.ktidValue = document.getElementById("ktid").value;
        $("#applyId").val(window.ktidValue)

        $(function(){
            <!-- laydate示例 -->
            layui.use('laydate', function(){
                var laydate = layui.laydate;
                laydate.render({
                    elem: '#laydate-demo-4',
                    range: true
                });
                var startDate = laydate.render({
                    elem: '#laydate-startTime',
                    max: $('#laydate-endTime').val(),
                    theme: 'molv',
                    trigger: 'click',
                    done: function(value, date) {
                        // 结束时间大于开始时间
                        if (value !== '') {
                            endDate.config.min.year = date.year;
                            endDate.config.min.month = date.month - 1;
                            endDate.config.min.date = date.date;
                        } else {
                            endDate.config.min.year = '';
                            endDate.config.min.month = '';
                            endDate.config.min.date = '';
                        }
                    }
                });
                var endDate = laydate.render({
                    elem: '#laydate-endTime',
                    min: $('#laydate-startTime').val(),
                    theme: 'molv',
                    trigger: 'click',
                    done: function(value, date) {
                        // 开始时间小于结束时间
                        if (value !== '') {
                            startDate.config.max.year = date.year;
                            startDate.config.max.month = date.month - 1;
                            startDate.config.max.date = date.date;
                        } else {
                            startDate.config.max.year = '';
                            startDate.config.max.month = '';
                            startDate.config.max.date = '';
                        }
                    }
                });
            });

            var kid = $("#ktid").val();
            var options = {
                url: prefix + "/bhyy/"+kid,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                pagination:false,

                columns: [

                    {
                        field : 'createTime',
                        title : '批阅时间',
                        width: 200

                    } ,
                    {
                        field : 'uname',
                        title : '批阅人',
                        width: 100
                    },
                    {
                        field : 'concate',
                        title : '内容',
                        width: 500
                     },
                    {
                        field : 'state',
                        title : '审核状态',
                        width: 100
                    }
                    //
                    // {
                    //     field: 'status',
                    //     title: '批阅状态',
                    //     align: 'center',
                    //     formatter: function(value, row, index) {
                    //         return $.table.selectDictLabel(datas, value);
                    //     }
                    // }
                ]
            };
            $.table.init(options);
        });
    </script>
    <script th:inline="javascript">
        var prefix = ctx + "system/apply";
        $("#form-apply-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.saveTab(prefix + "/edit", $('#form-apply-edit').serialize());
            }
        }

        $("input[name='signingData']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });



        $(".file-uploada").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload/hxkt',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true,
                allowedFileExtensions: ["pdf"],
                slugCallback: function(filename) {
                    if ($("input[name='topName']").val()===""){
                        $(".file-uploada").fileinput('clear');
                        $.modal.alertError("请先输入课题名称");
                        return false;
                    }
                    // 自定义文件名生成规则
                    fileExtension = filename.split('.').pop();
                    const year = new Date().getFullYear();
                    const newName = year +"-"+ $("input[name='topName']").val() +"-"+ "合同"+ "." + fileExtension;
                    return newName;
                },
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });
        $(".file-uploadb").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload/hxkt',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true,
                allowedFileExtensions: ["pdf"],
                slugCallback: function(filename) {
                    if ($("input[name='topName']").val()===""){
                        $(".file-uploadb").fileinput('clear');
                        $.modal.alertError("请先输入课题名称");
                        return false;
                    }
                    // 自定义文件名生成规则
                    fileExtension = filename.split('.').pop();
                    const year = new Date().getFullYear();
                    const newName = year +"-"+ $("input[name='topName']").val() +"-"+ "备案表"+ "." + fileExtension;
                    return newName;
                },
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });
    </script>
</body>

<body>
<style>
    .modal.inmodal .modal-dialog {
        width: auto;  /* 宽度自适应 */
        max-width: 50%;  /* 最大宽度限制，避免过宽 */
    }

    .modal.inmodal .modal-content {
        height: 800px;

    }

    /* 使模态框的内容区域自适应高度 */
    .modal-body {
        height: 500px;  /* 最大高度，避免溢出屏幕 */
        overflow-y: auto;  /* 如果内容超出高度，显示滚动条 */
    }

    .form-group-spacing {
        margin-bottom: 10px; /* 你可以根据需要调整这个值 */
    }
</style>

<div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
                </button>
                <i class="fa fa-laptop modal-icon"></i>
                <h4 class="modal-title">提交到账金额</h4>
<!--                <small class="font-bold">需要到账金额文件为佐证材料！</small>-->
            </div>
            <form class="form-horizontal m" id="form-apply-edit1">
            <div class="modal-body">
                <div class="col-xs-10">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">项目金额(万)：</label>
                        <div class="col-sm-8">
                            <input name="reAmount1" class="form-control" type="number" required>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="col-xs-10">
                        <div class="form-group">
                            <label class="col-sm-4 control-label is-required">到账日期：</label>
                            <div class="col-sm-8">
                                <div class="input-group date">
                                    <input name="accountData1" autocomplete="off"  class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="form-group-spacing" ></div>

                <div class="col-xs-10">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">到账文件：</label>
                        <div class="col-sm-8">
                            <input type="hidden" name="reamountUrl1">
                            <div class="file-loading">
                                <input class="form-control amountfile-upload" id="reamountUrl1" name="file" type="file" >
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            </form>
            <div class="modal-footer">
                <button type="button" id="close" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button"  class="btn btn-primary" onclick="submitAmount()">保存</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    function submitAmount() {
        if($("input[name='reAmount1']").val()==="")
            return $.modal.alertError("请添加到账金额");
        if($("input[name='accountData1']").val()==="")
            return $.modal.alertError("请添加到账时间");
        if($("input[name='reamountUrl1']").val()==="")
            return $.modal.alertError("请上传到账金额文件");
        if($("input[name='reAmount1']").val()!=="" && $("input[name='accountData1']").val()!=="" && $("input[name='reamountUrl1']").val()!==""){
            $("#reAmount").val($("input[name='reAmount1']").val());
            $("#accountData").val($("input[name='accountData1']").val());
            $("#reamountUrl").val($("input[name='reamountUrl1']").val());
            $("#close").click();
        }else{
            return $.modal.alertError("上传信息有误");
        }
        // $.operate.saveTab(prefix + "/Reamount");
    }
    $("input[name='accountData1']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    $(".amountfile-upload").fileinput({
        uploadUrl: ctx + 'common/upload/hxkt',
        maxFileCount: 1,
        autoReplace: true,
        allowedFileExtensions: ["pdf"],
        slugCallback: function(filename) {
            if ($("input[name='topName']").val()===""){
                $(".amountfile-upload").fileinput('clear');
                $.modal.alertError("请先输入课题名称");
                return false;
            }
            // 自定义文件名生成规则
            fileExtension = filename.split('.').pop();
            const year = new Date().getFullYear();
            const newName = year +"-"+ $("input[name='topName']").val() +"-"+ "金额佐证材料"+ "." + fileExtension;
            return newName;
        },
    }).on('fileuploaded', function (event, data, previewId, index) {
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    })
</script>
</body>
</html>